home *** CD-ROM | disk | FTP | other *** search
/ Champak 66 / Vol 66.iso / games / bluep.swf / scripts / __Packages / Music.as < prev    next >
Text File  |  2013-04-24  |  3KB  |  103 lines

  1. class Music
  2. {
  3.    function Music()
  4.    {
  5.       this.mySound = new Sound();
  6.       this.volume = 100;
  7.       this.currentTrack = "";
  8.       this.inCrossfade = false;
  9.       this.state = false;
  10.       this.changeSongs = true;
  11.       this.maxVolume = 60;
  12.    }
  13.    function SetMaxVolume(vol)
  14.    {
  15.       this.maxVolume = vol;
  16.    }
  17.    function SetTrack(setMusic)
  18.    {
  19.       trace(setMusic);
  20.       if(setMusic == this.currentTrack)
  21.       {
  22.          this.changeSongs = false;
  23.       }
  24.       else
  25.       {
  26.          this.changeSongs = true;
  27.          this.currentTrack = setMusic;
  28.       }
  29.    }
  30.    function Play()
  31.    {
  32.       this.mySound.stop();
  33.       this.mySound.attachSound(this.currentTrack);
  34.       this.volume = this.maxVolume;
  35.       this.mySound.setVolume(this.volume);
  36.       this.mySound.start(0,2000);
  37.       this.state = true;
  38.    }
  39.    function Stop()
  40.    {
  41.       this.mySound.stop();
  42.       this.state = false;
  43.    }
  44.    function PlayWithCrossFade(secondDuration)
  45.    {
  46.       if(this.changeSongs == true)
  47.       {
  48.          if(this.state == true)
  49.          {
  50.             this.inCrossfade = true;
  51.             this.targetVolume = 0;
  52.             var _loc2_ = secondDuration * 30;
  53.             this.volumeSpeed = (this.targetVolume - this.volume) / (_loc2_ / 2);
  54.          }
  55.          else
  56.          {
  57.             this.mySound.stop();
  58.             this.mySound.attachSound(this.currentTrack);
  59.             this.mySound.start(0,2000);
  60.             this.state = true;
  61.             this.inCrossfade = false;
  62.             this.targetVolume = this.maxVolume;
  63.             this.volume = 0;
  64.             this.mySound.setVolume(0);
  65.             _loc2_ = secondDuration * 30;
  66.             this.volumeSpeed = (this.targetVolume - this.volume) / _loc2_;
  67.          }
  68.       }
  69.    }
  70.    function RunPlayer()
  71.    {
  72.       if(this.targetVolume != this.volume)
  73.       {
  74.          var _loc2_ = undefined;
  75.          _loc2_ = this.volume + this.volumeSpeed;
  76.          if(this.volumeSpeed < 0 && _loc2_ < 0)
  77.          {
  78.             _loc2_ = 0;
  79.          }
  80.          else if(this.volumeSpeed > 0 && _loc2_ > this.targetVolume)
  81.          {
  82.             _loc2_ = this.targetVolume;
  83.          }
  84.          this.volume = _loc2_;
  85.          this.mySound.setVolume(_loc2_);
  86.       }
  87.       if(this.inCrossfade == true)
  88.       {
  89.          if(this.volume <= 0)
  90.          {
  91.             this.volumeSpeed *= -1;
  92.             this.inCrossfade = false;
  93.             this.targetVolume = this.maxVolume;
  94.             this.mySound.stop();
  95.             this.mySound.attachSound(this.currentTrack);
  96.             this.mySound.setVolume(0);
  97.             this.mySound.start(0,2000);
  98.             this.state = true;
  99.          }
  100.       }
  101.    }
  102. }
  103.